<template>
  <div class="add container">
    <h1 class="page-header">添加用户</h1>
    <form v-on:submit="addcustom">
         <div class="well"></div>
             <h4>用户信息</h4>
             <div class="form-group">
                  <label>姓名</label>
                <input type="text" class="form-control" placeholder="name" v-model="customee.name">
             </div>
              <div class="form-group">
                  <label>电话</label>
                <input type="text" class="form-control" placeholder="phone" v-model="customee.phone">
             </div>
              <div class="form-group">
                  <label>邮箱</label>
                <input type="text" class="form-control" placeholder="email" v-model="customee.email">
             </div>
            <button type="submit" class="btn btn-primary">添加</button>
    </form>
  </div>
</template>
<script>
import axios from 'axios'
export default {
      name:'tianjia',
      data(){
          return{
              customee:{}
          }
      },
      methods:{
          addcustom(e){
              console.log(123)
              if(!this.customee.name || !this.customee.email || !this.customee.phone){
                  console.log("请输入")
              }else{
    //               let newcustom={
    //                   name:this.customee.name,
    //                   email:this.customee.email,
    //                   phone:this.customee.phone
    //               }
    //                axios.post( 'http://localhost:3000/users', 'newcustom', {
    //           }).then(res=>{
    //                   console.log(res)
    // })
        axios({
   
    method: 'post',
    url: ('http://localhost:8082/users'),
    data: {
        name:this.customee.name,
       email:this.customee.email,
        phone:this.customee.phone
    }
}).then(res=>{
         console.log(res)
          this.$router.push({path:'/', query:{alert:"用户信息添加成功"}})
})

              }
             
              e.preventDefault();
          }
      }
     
      
}
</script>